/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ttt.nor2.util;

import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.util.TimeZone;
import java.util.Calendar;

public class StopWatch {

    TimeZone tz;
    Calendar startCal;
    Calendar endCal;
    double elap;

    public StopWatch() {

    }

    public void doStart() {

        tz = TimeZone.getTimeZone("CST");
        startCal = Calendar.getInstance(tz);

    }

    public String doStop() {

        endCal = Calendar.getInstance(tz);
        elap = (endCal.getTimeInMillis() - startCal.getTimeInMillis());

        NumberFormat formatter = new DecimalFormat("####.##");

        return formatter.format(elap);

    }

    public String getAvgWorkPerSec(int TotalWork) {

        try {

            double avgInSec =  ((double) TotalWork) / (elap / 1000);
            NumberFormat formatter = new DecimalFormat("####.##");
            return formatter.format(avgInSec);

        } catch ( Exception e ) {

            return "0";

        }

    }

    public String getAvgSecPerWork(int TotalWork) {

        try {

            double avgInSec = (elap / 1000) / ((double) TotalWork);
            NumberFormat formatter = new DecimalFormat("####.##");
            return formatter.format(avgInSec);

        } catch ( Exception e ) {

            return "0";

        }

    }

}
